package com.mes.web.controller.llm.Task;

import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.TimerTask;

import com.mes.entity.check.PatrolCheck;
import com.mes.entity.check.ReportCheck;
import com.mes.entity.check.TreeCheck;
import com.mes.entity.llm.FillRecord;
import com.mes.entity.warning.Warning;
import com.mes.service.llm.ChartLlmService;
import com.mes.service.warning.WarningService;
import com.mes.utils.PushExample;

/**
 * 执行任务
 * @Title:RunTask
 * @Package com.mes.web.controller.llm.Task
 * @author llm
 * @date 2019年6月6日
 * @version 1.0
 */
public class RankTask extends TimerTask{

	private ChartLlmService chartLlmService;
	private WarningService warningService;
	
	public RankTask(ChartLlmService chartLlmService, WarningService warningService){
		this.chartLlmService = chartLlmService;
		this.warningService = warningService;
	}
	
	public RankTask(){
		super();
	}
	
	/**       
	 *  质检填报查询  
	 */
	@Override
	public void run() {
		Date date = new Date();
		Map<String, Object> map = new HashMap<>();
		Warning w = new Warning();
		SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
		String today = sdf.format(date);
		map.put("today", today);
		//查询质检部门员工的权限
		List<FillRecord> list = chartLlmService.selectMenuByDepartment();
		int i;
		//根据权限查当天的填报记录
		for(FillRecord fr : list){
			if(fr != null){
				i = 0;
				if(fr.getMenuId() == 77 ){
					map.put("userId", fr.getUserId());
					List<TreeCheck> tclist =  chartLlmService.selectTreeCheckFillRecord(map);
					if(tclist.size() == 0){
						i = 1;
					}
				}else if(fr.getMenuId() == 78 ){
					map.put("userId", fr.getUserId());
					List<PatrolCheck> tclist =  chartLlmService.selectPatrolCheckFillRecord(map);
					if(tclist.size() == 0){
						i = 1;
					}
				}else if(fr.getMenuId() == 79 ){
					map.put("userId", fr.getUserId());
					List<ReportCheck> tclist =  chartLlmService.selectReportCheckFillRecord(map);
					if(tclist.size() == 0){
						i = 1;
					}
				}
				if(i == 1){
					w.setWsid(fr.getUserId());
					w.setWtype(fr.getMenuName());
					w.setWdate(today);
					w.setWstare("0");
					warningService.insert(w);
					PushExample.testSendPush("您有一个质检项未填报", fr.getMenuName(), fr.getUserId()+"", "1");
				}
			}
		}
	}
}
